﻿using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using HelixToolkit.Wpf;

namespace GameBoard
{
    public class InfoTextVisual : BillboardTextVisual3D, IVisual, IMoveable
    {
        private double _longestPictureSide;
        bool _belongsToMoveablePicture = false;
        public bool BelongsToMoveablePicture
        {
            get { return _belongsToMoveablePicture; }
        }
        public void PopulateVisualData(BaseVisualData theData)
        {
            _belongsToMoveablePicture = theData.BelongsToMoveablePicture;
            FactoryID = theData.FactoryID;

            var infoD = theData as InfoTextVisualData;
            Background = infoD.Background;
            Foreground = infoD.Foreground;
            Text = infoD.Text;
            FontSize = infoD.FontSize;
            _longestPictureSide = infoD.LongestPictureSide;
            Position = InfoTextLocation(infoD.Position);
        }


        public ModelVisual3D VisualElement
        {
            get { return this; }
        }

        public Guid FactoryID { get; set; }

        private Point3D InfoTextLocation(Point3D basePoint)
        {
            return new Point3D(basePoint.X
                , basePoint.Y + _longestPictureSide * 1.1,
                basePoint.Z + _longestPictureSide + 15);
        }



        public void MoveTo(Point3D newPoint)
        {
            var textAnimation = new Point3DAnimation(Position,
                InfoTextLocation(newPoint),
                new Duration(new TimeSpan(0, 0, 0, 1)));
            AnimationClock clock3 = textAnimation.CreateClock();
            ApplyAnimationClock(PositionProperty, clock3);
        }
    }
}